package com.wx.example.demo.annotations;

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

/**
 * @author wangxin
 * @time 2018/7/23 11:22
 */

public class Test {

    @Repeat("1")
    @Repeat("2")
    private String _new;

    @Repeats({@Repeat("3"),@Repeat("4")})
    private String _old;

    public static void main(String[] args) throws NoSuchFieldException {
        Annotation repeats[] = Test.class.getDeclaredField("_new").getAnnotationsByType(Repeat.class);
//        var repeats = Test.class.getAnnotationsByType(Repeat.class);
        List.of(repeats).forEach(System.out::println);

        Optional.ofNullable(Test.class.getDeclaredField("_new").getAnnotation(Repeats.class)).ifPresent(repeats1 -> {
            List.of(repeats1.value()).forEach(System.out::println);
        });

        System.out.println("------------------------------");
        Annotation oldRepeats[] = Test.class.getDeclaredField("_old").getAnnotationsByType(Repeat.class);
//        var repeats = Test.class.getAnnotationsByType(Repeat.class);
        List.of(oldRepeats).forEach(System.out::println);

        Optional.ofNullable(Test.class.getDeclaredField("_old").getAnnotation(Repeats.class)).ifPresent(repeats1 -> {
            List.of(repeats1.value()).forEach(System.out::println);
        });

    }
}
